A program consists of a script that can be compiled to into machine code so as to create a fully functional application. The Mac can be used without knowing about programming — only those inclined to this odd form of enjoyment need worry about it!
Standard Programming Languages
qqqqqqqqqqqqqqqqqqqqqqqqq
An interpreter application executes each line of the program every time it’s run. This means the program runs slowly, and can’t be used as a stand-alone application. However, the effects of any changes that you make can be seen immediately.
A compiler translates the entire program into pure code before you run the program. The compiled result can be used as a stand-alone application that runs at full speed. The need to recompile the program for every minor alteration can make this a tedious process!
Programming can operate at several levels:-
Machine Code
This consists of the pure binary codes and data as used by a particular microprocessor. Very few programmers ever work at this rudimentary level.
Assembly Language
This uses hexadecimal (hex) values for data and three-letter mnemonics for instruction codes. Some programmers like working at this low level!
High Level Languages
These languages are written in a pseudo-English form that is reasonably easy to understand. At the same time it doesn’t require much software to convert the program into code. Common high-level programming languages include:-
Language Notes
APL (A Programming Language) Matrix manipulation
BASIC (Beginners All-purpose Symbolic Easy to use but difficult
Instruction Code) to read existing programs
C Widely used and powerful
COBOL (Common Business Oriented Language) For text and records
Forth Uses reverse-Polish notation
FORTRAN (Formula Translation) For mathematics solutions
LISP (List Processing) For building lists
Logo
Pascal
Modula-2 Real-time control
The best languages are object orientated. This means that the programmer can achieve results without a deep understanding of a particular micro.
The Macintosh Programmers Workshop (MPW) is a complete development system comprising of editor shell, used to to edit source code, to which compilers for C, Pascal or Fortran can be added. Think C is an alternative development environment for C.
AppleScript and IAC
qqqqqqqqqqqqqqq
Using AppleScript
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
AppleScript is a simple programming system that comes as part of the system. By using the Script Editor you can create a macro that can work as a stand-alone application. Such a macro can undertake similar activities to those provided by QuicKeys or KeyQuencer
AppleScript, although slower than these other macro applications, is also much more powerful. This is because it can actually control an application from within its macro script — assuming the application is actually scriptable. You can check an application’s suitability by referring to the documentation that came with it.
Userland Frontier can be used as an alternative to AppleScript.
Installation
The following items should reside in the System Installer:-
z In the Extensions folder:-
AppleScript extension
Finder Scripting Extension
Scripting Additions folder
z In the AppleScript folder:-
AppleScript Guide (SimpleText)
Script Editor
Automated Tasks folder (with an alias in Apple Menu Items)
The Automated Tasks Folder
The Automated Tasks folder contains some useful files to get you started — including a number of applications created with AppleScript. These come in two forms:-
  Applications with a downward arrow icon are droplets. They operate on files
— you either drop files onto the application or launch it and open them.
  Applications with a simple icon don’t operate on specific files.
You simply double-click on them to launch them.
The Automated Tasks folder contains:-
z Add Alias to Apple Menu
You can either select it and run it or drag a file onto it.
z Create Alias Folder
If you drop a folder called Fred onto this, a folder is created containing aliases of all the files in
Fred — or you can click on this file and it will ask you to name the folder on which to operate.
z Eject All
z Find Original
z Hide/Show Folder Sizes
z New Item Watcher
If you specify a folder the application will monitor it for any changes made to it.
Using the Script Editor
The Script Editor should be assigned at least 700 K of memory. To create your first scripts you should use the Record Macro feature — this generates a script from your own actions. You can then modify or add to this as necessary. You can then Save the result as a self-contained application, as an AppleScript document or as a text file.
Problems with AppleScript
You may encounter problems when using AppleScript-based enhancements over a range of applications — not all applications will accept the same script! For example, Font-o-rama (an excellent application that displays and gives keyboard access to your fonts) works with many applications, but not with ClarisWorks. It’s not really anyone’s fault — although you could blame Apple for not setting rigid standards in the first place!
Things aren’t so bad if you’re controlling the Finder in conjunction with the Finder Scripting Extension — its scripts never change! CanIt! (an extension and control panel combination) uses Finder scripting to simplify file trashing — just select the file, press † with a specified key and it’s gone!
Inter-application Communication
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
The Mac system allows information to be passed between two processes. Usually this involves a pair of applications and is known as Inter-application communication (IAC).
Apple Events
Apple Events (AEs) are a subset of the high-level events used by applications such as AppleScript and the Finder. They give the destination process a full set of instructions on how it should behave. This makes AEs a flexible but cumbersome form of IAC.
They come in the following sets:-
z Required
All processes must accept the following instructions:-
Open Application
Open Documents
Print Documents
Quit Application
z Core
Activities necessary for most processes:-
Cut, Copy, Paste
Move, Save
Delete, Undo
z Functional Area
Activities for a particular class of process, such as a drawing program.
z Custom
Activities for software development.
· Only the required and core sets are specifically defined. The others can be
implemented in slightly different ways!
Publish and Subscribe
This is a simple one-way form of IAC. Any document, created in any application, can publish specified data from within itself to a designated file. A second file (created in the same application or in another application) can then subscribe to this designated file. If the original document is updated at a later date the designated file and the subscribing document can be automatically or manually updated.
The actual data is transferred in a similar manner as used in Copy and Paste.
Process to Process Communication (PPC)
PPC is a low-level form of IAC. It establishes a communication session with the destination process before sending data. Having done this, the information can be sent in a simple form — this makes it less flexible than Apple Events.
Here’s an example of PPC in action:-
Process 1 opens port A
Process 2 opens port B
Process 1 tells the System it’s ready for PPC
Process 2 asks the System for a session with port A
PPC is usually asynchronous — each process executes functions which should give an instant response. The system may provide a call-back to confirm any operations or flags. Since PPC works in both directions the software can report any problems that occur.